<?php
//判断用户名是否被占用
function isAllreadyHasSameUserName($username = ''){
    if(!$username){
        return true;
    }
    
    $userModel = Helper::load('User');
    $cnt = $userModel->Where(['user_name' => $username, 'isdelete' => 0])->Total();
    
    if($cnt){
        return true;
    }
    
    return false;
}

//判断当前用户是否存在相同角色关系
function isAllreadyHasSameUserRelation($user_id = 0, $role_id = 0){
    if(!$user_id || !$role_id){
        return true;
    }
    
    $UserRoleRelationModel = Helper::load('User_role_relation');
    $cnt = $UserRoleRelationModel->Where(['user_id' => $user_id, 'role_id' => $role_id])->Total();
    
    if($cnt){
        return true;
    }
    
    return false;
}

//判断是否已存在当前班级成员关系
function isAllreadyHasSameClassMember($class_id, $user_id, $cm_type, $subject_d_ids = ''){
    $ClassMemberModel = Helper::load('Class_member');
    
    if($cm_type != 22){
        $subject_d_ids = '';
    }
    
    $cnt = $ClassMemberModel->Where(['class_id' => $class_id, 'user_id' => $user_id, 'cm_type' => $cm_type, 'subject_d_ids' => $subject_d_ids])->Total();
    
    if($cnt){
        return true;
    }
    
    return false;
}